package api;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 王艺锡
 * @version 1.0
 * InetAddress类的使用
 */
public class API_ {
    public static void main(String[] args) throws UnknownHostException {
        //1.获取本机的 InetAddress 对象(计算机名称和ip地址)
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);

        //2.根据主机名，获取InetAddress 对象(计算机名称和ip地址)
        InetAddress host1 = InetAddress.getByName("WYX");
        System.out.println(host1);

        //3.域名，获取InetAddress 对象(域名和ip地址)
        InetAddress host2 = InetAddress.getByName("www.baidu.com");
        System.out.println(host2);

        //4.通过 InetAddress 对象，获取ip地址
        String hostAddress = host2.getHostAddress();
        System.out.println(hostAddress);

        //5.通过 InetAddress 对象，获取主机名或域名
        String hostName = host2.getHostName();
        System.out.println(hostName);

    }
}
